#include <iostream>
#include "GraphWeightedMatrix.h"

using namespace std;

GraphWeightedMatrix::GraphWeightedMatrix(summit_t n, edges_t m) : GraphWeighted(n,m)
{
  cerr << "Constructeur paramétré de GraphWeightedMatrix" << endl;
  weight = new weight_t*[n]; 
  for(int i(0);i<n;i++)
    {
      weight[i]= new weight_t[n];
      for(int j(0);j<n;j++)
	{
	  weight[i][j] = -1; //Rien n'est connexe
	}
    }
  summit_nb = n;
  edges_nb = m;
}

GraphWeightedMatrix::~GraphWeightedMatrix()
{
  // Allocation dynamique
  std::cout << "Suppression de la matrice de poids " << endl; 
  for(int i = 0; i < summit_nb; i++) {
    delete [] weight[i];
  }
  delete [] weight;
}

weight_t GraphWeightedMatrix::getWeight(summit_t i, summit_t j) const
{
  return weight[i][j]; //On retourne -1 si pas connectés
}

void GraphWeightedMatrix::setWeight(summit_t i, summit_t j, weight_t t)
{
  if ((i<summit_nb) && (j<summit_nb) && (i>=0) && (j>=0) && (i!=j))
  {
    weight[i][j]=t;
  }
}

void GraphWeightedMatrix::printGraph()const
{
  for(int i(0);i<summit_nb;i++)
    {
      for(int j(0);j<summit_nb;j++)
	{
	  cout << " | " << weight[i][j];
	}
      std::cout << " |"<< endl;
    }
}
